<?php
/**商铺管理控制器
 * @Author: 976123967@qq.com
 * @Date:   2014-08-31 11:38:15
 * @Last Modified by:   chen
 * @Last Modified time: 2014-08-31 23:47:03
 */
class ShopControl extends CommonControl{
	/**
	 * [__auto 初始化]
	 * @return [type] [description]
	 */
	public function __auto()
	{
		$this->model = K('Shop');
	}

	/**
	 * [index 商铺列表]
	 * @return [type] [description]
	 */
	public function index()
	{
		
		$count = $this->model->count();
		$page = new Page($count,20);
		$shop = $this->model->get_shop_all(null,$page->limit());
		$this->assign('page',$page->show());
		$this->assign('shop',$shop);
		$this->display();
	}

	/**
	 * [add 添加商铺]
	 */
	public function add()
	{
		if(IS_POST)
		{
			if(!$this->model->create()) 
				$this->error($this->model->error);
			$this->model->add_shop();
			$this->success('商铺添加成功',U('Shop/index'));
		}
		$this->display();
	}

	/**
	 * [edit 编辑]
	 * @return [type] [description]
	 */
	public function edit()
	{
		if(IS_POST)
		{
			if(!$this->model->create()) 
				$this->error($this->model->error);
			$this->model->edit_shop();
			$this->success('商铺编辑成功',U('Shop/index'));
		}

		$shopid = Q('get.shopid',null,'intval');
		$data = $this->model->get_shop_one($shopid);

		if(!$data) $this->error('商铺信息不存在',U('Shop/index'));

		$this->assign('data',$data);

		$this->display();

	}

	/**
	 * [del 删除]
	 * @return [type] [description]
	 */
	public function del()
	{
		$shopid = Q('get.shopid',null,'intval');
		$data = $this->model->get_shop_one($shopid);

		if(!$data) $this->error('商铺信息不存在',U('Shop/index'));

		if(!$this->model->del_shop($shopid)) $this->error($this->model->error,U('Shop/index'));

		$this->success('商铺删除成功',U('Shop/index'));
	}



}